package com.hzdesk.media.koreabatchmatvector.dao;

import android.content.Context;
import android.util.Log;

import com.hzdesk.media.koreabatchmatvector.bean.AdvertisingBeanDao;
import com.hzdesk.media.koreabatchmatvector.bean.ConfigFileBean;
import com.hzdesk.media.koreabatchmatvector.bean.MeetInfoBean;
import com.hzdesk.media.koreabatchmatvector.bean.MeetInfoBeanDao;

import java.util.List;

/**
 * Created by Administrator on 2018/7/4.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public class MeetInfoDaoUtils {
    private static final String TAG = MeetInfoDaoUtils.class.getSimpleName();
    private DaoManager daoManager;


    public MeetInfoDaoUtils(Context context) {
        daoManager = DaoManager.getInstance();
        daoManager.init(context);
    }
    /**
     * @desc 插入数据
     * */
    public boolean insertMeetInfo(MeetInfoBean bean){
        boolean flag = false;
        MeetInfoBeanDao dao = daoManager.getDaoSession().getMeetInfoBeanDao();
        try {
           // 插入前清空数据
            List<MeetInfoBean> mlist =  query();
           // Log.e("DataConversionUtils", "ConversionUtilsMeetInfo e : "+ mlist.size());
            if(mlist != null && mlist.size() > 0){
                clear();
            }
            flag = dao.insertOrReplace(bean) == -1? false:true;
            //flag = dao.insertOrReplace(bean) == -1? false:true;
        } catch (Exception e) {
            Log.e("DataConversionUtils", "ConversionUtilsMeetInfo e : "+ e);
        }

        return flag;
    }
    /**
     * @desc 清空数据
     * */
    public void clear(){
        MeetInfoBeanDao dao = daoManager.getDaoSession().getMeetInfoBeanDao();
        try {
            dao.deleteAll();
        } catch (Exception e) {

        }
    }
    /***
     * @desc 查询数据
     * */

    public List<MeetInfoBean> query(){
        MeetInfoBeanDao dao = daoManager.getDaoSession().getMeetInfoBeanDao();
        List<MeetInfoBean>  bean = null ;
        try {
             bean =   dao.loadAll();
        } catch (Exception e) {
        }
        return bean;
    }
}
